package com.example.group.network.express_plus_app;

import java.util.HashMap;
import java.util.List;

import android.app.Application;
import android.graphics.Bitmap;
import android.util.Log;

import com.example.group.network.express_plus_app.Dao.AppDatabase;
import com.example.group.network.express_plus_app.Dao.UserDao.UserDao;
import com.example.group.network.express_plus_app.data.model.LoggedInUser;

/**
 * Created by ouyangshen on 2016/10/1.
 */
public class MainApplication extends Application {
	AppDatabase appDatabase;
	private final static String TAG = "MainApplication";
	private static MainApplication mApp;
	public HashMap<String, String> mInfoMap = new HashMap<String, String>();
	
	public static MainApplication getInstance() {
		return mApp;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		mApp = this;
		appDatabase= AppDatabase.getsInstance(this);
		//在aPP启动时加载用户信息到
		UserDao userDao = appDatabase.userDao();
		List<LoggedInUser> loggedInUsers = userDao.loadUsers();
		if (loggedInUsers.size()>0){

			LoggedInUser loggedInUser = loggedInUsers.get(0);
			mInfoMap.put("phone",loggedInUser.getPhone());
			mInfoMap.put("token",loggedInUser.getAccessToken());
			mInfoMap.put("user_face",loggedInUser.getImagePath());
			mInfoMap.put("net_name",loggedInUser.getDisplayName());
			mInfoMap.put("delivery_address",loggedInUser.getDeliveryAddress());
			Log.d(TAG, "APP启动，用户信息"+loggedInUser.getPhone()+"被加入内存");
/*			mInfoMap.put("display_name",loggedInUser.getDisplayName());
			mInfoMap.put("image_path",loggedInUser.getImagePath());*/
		}
	}

	//在app退出时
	@Override
	public void onTerminate() {
		Log.d(TAG, "onTerminate");
		super.onTerminate();
	}
	
	public HashMap<Long, Bitmap> mIconMap = new HashMap<Long, Bitmap>();
	
}
